package com.iotproject.eduservice.controller;


import com.iotproject.commonutils.R;
import com.iotproject.eduservice.entity.subject.OneSubject;
import com.iotproject.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-11-07
 */
@RestController
@RequestMapping("/eduservice/edu-subject")
//d @CrossOrigin
public class EduSubjectController {
    @Autowired
    EduSubjectService eduSubjectService;
    //传入Excel文件，将内容存储到数据库
    @PostMapping("addSubject")
    public R upload(MultipartFile file) {
        eduSubjectService.importSubjectData(file, eduSubjectService);
        return R.ok();
    }

    @GetMapping("getAll")
    public R getAll() {
        List<OneSubject> res = eduSubjectService.getAllSubject();
        return R.ok().data("list", res);
    }

}

